using System.Threading;
using UnityEngine;

namespace JH
{
    public class TestTween : MonoBehaviour
    {
        [SerializeField] private RectTransform rect;

        [SerializeField] private Ease ease;

        private CancellationTokenSource _tokenSource;

        void Update()
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                _tokenSource?.Cancel();
                _tokenSource = CancellationTokenSource.CreateLinkedTokenSource(destroyCancellationToken);
                rect.Tween(50f, 1920f - 50f,
                    t =>
                    {
                        Debug.Log(t);
                        rect.anchoredPosition = new Vector2(t, rect.anchoredPosition.y);
                    }, 1f,
                    _tokenSource.Token, ease);
            }
        }
    }
}